"""
@Author    : ghenyar
@Time      : 2025/8/28 16:31
@File      : login
@Desc      : 
"""
from pydantic import BaseModel, field_validator

from app.common.exception.exceptions import ValidationException


class LoginSchemas(BaseModel):
    username: str
    password: str
    captcha: str
    captcha_key: str

    @field_validator("username")
    def validate_username(cls, v):
        if not v:
            raise ValidationException("登录账号不能为空")
        if len(v) < 3:
            raise ValidationException("请输入3~12位的账号")
        return v

    @field_validator('password')
    def validate_password(cls, v):
        if not v:
            raise ValidationException("登录密码不能空")
        if len(v) < 6:
            raise ValidationException("请输入6位或6位以上的登录密码")
        return v

    @field_validator("captcha")
    def validate_captcha(cls, v):
        if not v:
            raise ValidationException("验证码不能为空")
        return v

    @field_validator("captcha_key")
    def validate_captcha_key(cls, v):
        if not v:
            raise ValidationException("验证码Key不能为空")
        return v
